package com.ewanghuiju.app.ui.my.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.my.VipUpdataContract;
import com.ewanghuiju.app.component.RxBus;
import com.ewanghuiju.app.model.bean.response.BuyDailiInfoBean;
import com.ewanghuiju.app.model.event.SendEvent;
import com.ewanghuiju.app.presenter.my.VipUpdataPresenter;
import com.ewanghuiju.app.ui.pintuan.activity.PintuanRuleActivity;
import com.ewanghuiju.app.util.LoadingDialogUtils;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.ewanghuiju.app.widget.FixedAspectRatioLinerLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.style.cityjd.JDCityConfig;
import com.lljjcoder.style.cityjd.JDCityPicker;
import com.muddzdev.styleabletoast.StyleableToast;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 会员升级页面 确认
 * @time 2020/2/19
 */
public class VipUpdataActivity extends BaseActivity<VipUpdataPresenter> implements VipUpdataContract.View {
    @BindView(R.id.layout_vip_card)
    FixedAspectRatioLinerLayout layoutVipCard;
    @BindView(R.id.layout_price)
    RelativeLayout layoutPrice;
    @BindView(R.id.tv_sfk)
    TextView tvSfk;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_now_pay)
    TextView tvNowPay;
    //购买区域代理lab
    @BindView(R.id.tv_buy_area_daili)
    TextView tvBuyAreaDaili;
    @BindView(R.id.tv_updata_water_num)
    TextView tvUpdataWaterNum;
    @BindView(R.id.tv_introduce)
    TextView tvIntroduce;
    @BindView(R.id.tv_select_area)
    TextView tvSelectArea;

    private String introduceTitle = "";
    private String content = "";

    private String area_id = "";

    @Override
    protected int getLayout() {
        return R.layout.activity_vip_updata;
    }

    @Override
    protected void initEventAndData() {
        LoadingDialogUtils.show(mContext);
        mPresenter.getPtibuyDailiInfo();
    }

    @Override
    protected int getTitleIntText() {
        return R.string.updata_area_daili;
    }

    @OnClick({R.id.layout_area_select, R.id.tv_now_pay, R.id.cv_buy_introduce})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.layout_area_select:
                //地区选择
                JDCityPicker cityPicker = new JDCityPicker();
                JDCityConfig jdCityConfig = new JDCityConfig.Builder().build();

                jdCityConfig.setShowType(JDCityConfig.ShowType.PRO_CITY_DIS);
                cityPicker.init(this);
                cityPicker.setConfig(jdCityConfig);
                cityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
                    @Override
                    public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                        area_id = district.getId();
                        tvSelectArea.setText(province.getName() + city.getName() + district.getName());
                    }

                    @Override
                    public void onCancel() {
                    }
                });
                cityPicker.showCityPicker();
                break;

            case R.id.tv_now_pay:
                if (TextUtils.isEmpty(area_id)) {
                    StyleableToast.makeText(mContext, "请选择地区", R.style.mytoast).show();
                    return;
                }
                LoadingDialogUtils.show(mContext);
                mPresenter.ptibuyDaili(area_id);
//                new StartActivityUtil(mContext, MessageListActivity.class).putExtra(Constants.MESSAGE_TYPE, Constants.SETTING_MESSAGE)
//                        .startActivity();
                break;
            case R.id.cv_buy_introduce:
                new StartActivityUtil(mContext, PintuanRuleActivity.class)
                        .putExtra(Constants.RULE_TITLE, introduceTitle)
                        .putExtra(Constants.RULE_CONTENT, content)
                        .startActivity(true);
                break;
            default:
                break;
        }
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(mToolbar, true)
                .statusBarDarkFont(true)
                .init();
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    public void showPtibuyDailiInfo(BuyDailiInfoBean buyDailiInfoBean) {
        //获取信息成功
        LoadingDialogUtils.dismissDialog_ios();
        if (buyDailiInfoBean != null) {
            tvBuyAreaDaili.setText(buyDailiInfoBean.getUpgrade_daili() + "水滴购买区域代理");
            tvUpdataWaterNum.setText(buyDailiInfoBean.getUpgrade_daili() + "水滴");
            tvPrice.setText(buyDailiInfoBean.getUpgrade_daili());
            if (buyDailiInfoBean.getGoumaixuzhi() != null) {
                tvIntroduce.setText(TextUtils.isEmpty(buyDailiInfoBean.getGoumaixuzhi().getIntroduce()) ? "" : buyDailiInfoBean.getGoumaixuzhi().getIntroduce());
                introduceTitle = buyDailiInfoBean.getGoumaixuzhi().getIntroduce();
                content = buyDailiInfoBean.getGoumaixuzhi().getContent();
            }
        }
    }

    @Override
    public void showbuyDailiSuccess() {
        //购买区域代理成功
        LoadingDialogUtils.dismissDialog_ios();
        StyleableToast.makeText(mContext, "购买成功", R.style.mytoast).show();
        //刷新用户信息
        RxBus.getDefault().post(new SendEvent("", Constants.TYPE_GET_USERINFO));
        onBackPressedSupport();
    }
}
